// string_test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iterator>

void Split_test();
void Split_v1_test(tstringc& tscSrc, tstringc& tscDelimiters);
void Split_v2_test(tstringc& tscSrc, tstringc& tscDelimiters);
void Split_v3_test(tstringc& tscSrc, tstringc& tscDelimiters);

void Sub_test();

void Convert_test();

void Num_To_String_test();
void U64To_test(u64 v);
void U32To_test(u32 v);
void U16To_test(u16 v);
void U8To_test(u8 v);
void I64To_test(i64 v);
void I32To_test(i32 v);
void I16To_test(i16 v);
void I8To_test(i8 v);

void String_To_Num_test();
void ToU64_test();
void ToU32_test();

void Check_test();
void IsVisible_test();

int _tmain(int argc, _TCHAR* argv[])
{
//	Split_test();
	Sub_test();
//	Convert_test();
//	Num_To_String_test();
//	String_To_Num_test();
//	Check_test();
	
	getchar();
	return 0;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

void Split_test()
{
	tcout << _T("-------- Split_test --------") << endl;

	tcout << _T("-- Split_v1_test") << endl;
	Split_v1_test(_T(""), _T(""));
	Split_v1_test(_T("1,2,3"), _T(""));
	Split_v1_test(_T("1,2,3"), _T(","));
	Split_v1_test(_T(",,1,2,3,,"), _T(","));
	Split_v1_test(_T(";,1;,2,3,;"), _T(",;"));
	tcout << endl;

	tcout << _T("-- Split_v2_test") << endl;
	Split_v2_test(_T(""), _T(""));
	Split_v2_test(_T("1,2,3"), _T(""));
	Split_v2_test(_T("1,2,3"), _T(","));
	Split_v2_test(_T(",,1,2,3,,"), _T(","));
	Split_v2_test(_T(";,1,;2,3,;"), _T(",;"));
	tcout << endl;

	tcout << _T("-- Split_v3_test") << endl;
	Split_v3_test(_T(""), _T(""));
	Split_v3_test(_T("1,2,3"), _T(""));
	Split_v3_test(_T("1,2,3"), _T(","));
	Split_v3_test(_T(",,1,2,3,,"), _T(","));
	Split_v3_test(_T(";,1,;2,3,;"), _T(",;"));
	Split_v3_test(_T("abc \"aa,ee\""), _T(",;"));
	Split_v3_test(_T("abc \"aa,ee\"  "), _T(",;"));
	Split_v3_test(_T(" abc\"d,e\";f g "), _T(",;"));
	Split_v3_test(_T("\"a;bc\"\"d,e\";f g "), _T(",;"));
	tcout << endl;

	tcout << endl;
}

void Split_v1_test(tstringc& tscSrc, tstringc& tscDelimiters)
{
	vector<tstring > vct;
	cz_string_SplitT_v1(tscSrc, tscDelimiters, vct);
	tcout << vct.size() << _T(": ");
	copy(vct.begin(), vct.end(), ostream_iterator<tstring, tchar >(tcout, _T(" / ")));
	tcout << endl;
}

void Split_v2_test(tstringc& tscSrc, tstringc& tscDelimiters)
{
	vector<tstring > vct;
	cz_string_SplitT_v2(tscSrc, tscDelimiters, vct);
	tcout << vct.size() << _T(": ");
	copy(vct.begin(), vct.end(), ostream_iterator<tstring, tchar >(tcout, _T(" / ")));
	tcout << endl;
}

void Split_v3_test(tstringc& tscSrc, tstringc& tscDelimiters)
{
	vector<tstring > vct;
	cz_string_SplitT_v3(tscSrc, tscDelimiters, vct);
	tcout << vct.size() << _T(": ");
	copy(vct.begin(), vct.end(), ostream_iterator<tstring, tchar >(tcout, _T(" / ")));
	tcout << endl;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

void Sub_test()
{
	tstring tsc = _T("c:\\123\\456");

	tcout << _T("-------- Sub_test --------") << endl;

	tcout << _T("-- TrimLeft_test") << endl;
	tcout << cz_string_TrimLeftT(tsc, _T("c")) << endl;
	tcout << cz_string_TrimLeftT(tsc, _T("c:\\")) << endl;
	tcout << cz_string_TrimLeftT(tsc, _T(" ")) << endl;
	tcout << endl;

	tcout << _T("-- TrimRight_test") << endl;
	tcout << cz_string_TrimRightT(tsc, _T("6")) << endl;
	tcout << cz_string_TrimRightT(tsc, _T("65\\4")) << endl;
	tcout << cz_string_TrimRightT(tsc, _T(" ")) << endl;
	tcout << endl;

	tcout << _T("-- Trim_test") << endl;
	tcout << cz_string_TrimT(tsc, _T("6c:")) << endl;
	tcout << cz_string_TrimT(tsc, _T("c:65\\")) << endl;
	tcout << cz_string_TrimT(tsc, _T(" c")) << endl;
	tcout << cz_string_TrimT(tsc, _T(" 65")) << endl;
	tcout << cz_string_TrimT(tsc, _T(" ?:\\")) << endl;
	tcout << endl;

	tcout << _T("-- GetLeft_test") << endl;
	tcout << cz_string_GetLeftT(tsc, _T('\\')) << endl;
	tcout << cz_string_GetLeftT(tsc, _T('\\'), CZ_STRING_INCLUDE) << endl;
	tcout << cz_string_GetLeftT(tsc, _T('#')) << endl;
	tcout << cz_string_GetLeftT(tsc, _T('#'), CZ_STRING_EMPTY) << endl;
	tcout << endl;

	tcout << _T("-- GetRight_test") << endl;
	tcout << cz_string_GetRightT(tsc, _T('\\')) << endl;
	tcout << cz_string_GetRightT(tsc, _T('\\'), CZ_STRING_INCLUDE) << endl;
	tcout << cz_string_GetRightT(tsc, _T('#')) << endl;
	tcout << cz_string_GetRightT(tsc, _T('#'), CZ_STRING_EMPTY) << endl;
	tcout << endl;

	tcout << _T("-- ReverseGetLeft_test") << endl;
	tcout << cz_string_ReverseGetLeftT(tsc, _T('\\')) << endl;
	tcout << cz_string_ReverseGetLeftT(tsc, _T('\\'), CZ_STRING_INCLUDE) << endl;
	tcout << cz_string_ReverseGetLeftT(tsc, _T('#')) << endl;
	tcout << cz_string_ReverseGetLeftT(tsc, _T('#'), CZ_STRING_EMPTY) << endl;
	tcout << endl;

	tcout << _T("-- ReverseGetRight_test") << endl;
	tcout << cz_string_ReverseGetRightT(tsc, _T('\\')) << endl;
	tcout << cz_string_ReverseGetRightT(tsc, _T('\\'), CZ_STRING_INCLUDE) << endl;
	tcout << cz_string_ReverseGetRightT(tsc, _T('#')) << endl;
	tcout << cz_string_ReverseGetRightT(tsc, _T('#'), CZ_STRING_EMPTY) << endl;
	tcout << endl;

	tcout << endl;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

void Convert_test()
{
	tcout << _T("-------- Convert_test --------") << endl;

	tcout << _T("-- ToLower_test") << endl;
	tcout << cz_string_ToLowerT(_T("123abcABC")) << endl;
	tcout << cz_string_ToLowerT(_T("")) << endl;
	tcout << endl;

	tcout << _T("-- ToUpper_test") << endl;
	tcout << cz_string_ToUpperT(_T("123abcABC")) << endl;
	tcout << cz_string_ToUpperT(_T("")) << endl;
	tcout << endl;

	tcout << endl;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

void Num_To_String_test()
{
	tcout << _T("-------- Num_To_String_test --------") << endl;

	tcout << _T("-- U64To_test") << endl;
	U64To_test(0xffffffffffffffff);
	U64To_test(0xfffffffffffffff);
	U64To_test(0x123456);
	U64To_test(0x0);
	tcout << endl;

	tcout << _T("-- U32To_test") << endl;
	U32To_test(0xffffffff);
	U32To_test(0xfffffff);
	U32To_test(0x123);
	U32To_test(0x0);
	tcout << endl;

	tcout << _T("-- U16To_test") << endl;
	U16To_test(0xffff);
	U16To_test(0xfff);
	U16To_test(0x123);
	U16To_test(0x0);
	tcout << endl;

	tcout << _T("-- U8To_test") << endl;
	U8To_test(0xff);
	U8To_test(0xf);
	U8To_test(0x12);
	U8To_test(0x0);
	tcout << endl;

	tcout << _T("-- I64To_test") << endl;
	I64To_test(0xffffffffffffffff);
	I64To_test(0xfffffffffffffff);
	I64To_test(0x123456);
	I64To_test(0x0);
	tcout << endl;

	tcout << _T("-- I32To_test") << endl;
	I32To_test(0xffffffff);
	I32To_test(0xfffffff);
	I32To_test(0x123);
	I32To_test(0x0);
	tcout << endl;

	tcout << _T("-- I16To_test") << endl;
	I16To_test((i16)0xffff);
	I16To_test(0xfff);
	I16To_test(0x123);
	I16To_test(0x0);
	tcout << endl;

	tcout << _T("-- I8To_test") << endl;
	I8To_test((i8)0xff);
	I8To_test(0xf);
	I8To_test(0x12);
	I8To_test(0x0);
	tcout << endl;

	tcout << endl;
}

void U64To_test(u64 v)
{
	tcout << _T("none: ") << cz_string_U64ToT(v) << endl;
	tcout << _T("hex: ") << cz_string_U64ToT(v, CZ_STRING_HEX) << endl;
	tcout << _T("oct: ") << cz_string_U64ToT(v, CZ_STRING_OCT) << endl;
	tcout << _T("hex,fill: ") << cz_string_U64ToT(v, CZ_STRING_HEX | CZ_STRING_FILL) << endl;
	tcout << _T("hex,prefix: ") << cz_string_U64ToT(v, CZ_STRING_HEX | CZ_STRING_PREFIX) << endl;
	tcout << _T("hex,fill,prefix: ") << cz_string_U64ToT(v, CZ_STRING_HEX | CZ_STRING_FILL | CZ_STRING_PREFIX) << endl;
	tcout << _T("oct,prefix: ") << cz_string_U64ToT(v, CZ_STRING_OCT | CZ_STRING_PREFIX) << endl;
}

void U32To_test(u32 v)
{
	tcout << _T("none: ") << cz_string_U32ToT(v) << endl;
	tcout << _T("hex: ") << cz_string_U32ToT(v, CZ_STRING_HEX) << endl;
	tcout << _T("oct: ") << cz_string_U32ToT(v, CZ_STRING_OCT) << endl;
	tcout << _T("hex,fill: ") << cz_string_U32ToT(v, CZ_STRING_HEX | CZ_STRING_FILL) << endl;
	tcout << _T("hex,prefix: ") << cz_string_U32ToT(v, CZ_STRING_HEX | CZ_STRING_PREFIX) << endl;
	tcout << _T("hex,fill,prefix: ") << cz_string_U32ToT(v, CZ_STRING_HEX | CZ_STRING_FILL | CZ_STRING_PREFIX) << endl;
	tcout << _T("oct,prefix: ") << cz_string_U32ToT(v, CZ_STRING_OCT | CZ_STRING_PREFIX) << endl;
}

void U16To_test(u16 v)
{
	tcout << _T("none: ") << cz_string_U16ToT(v) << endl;
	tcout << _T("hex: ") << cz_string_U16ToT(v, CZ_STRING_HEX) << endl;
	tcout << _T("oct: ") << cz_string_U16ToT(v, CZ_STRING_OCT) << endl;
	tcout << _T("hex,fill: ") << cz_string_U16ToT(v, CZ_STRING_HEX | CZ_STRING_FILL) << endl;
	tcout << _T("hex,prefix: ") << cz_string_U16ToT(v, CZ_STRING_HEX | CZ_STRING_PREFIX) << endl;
	tcout << _T("hex,fill,prefix: ") << cz_string_U16ToT(v, CZ_STRING_HEX | CZ_STRING_FILL | CZ_STRING_PREFIX) << endl;
	tcout << _T("oct,prefix: ") << cz_string_U16ToT(v, CZ_STRING_OCT | CZ_STRING_PREFIX) << endl;
}

void U8To_test(u8 v)
{
	tcout << _T("none: ") << cz_string_U8ToT(v) << endl;
	tcout << _T("hex: ") << cz_string_U8ToT(v, CZ_STRING_HEX) << endl;
	tcout << _T("oct: ") << cz_string_U8ToT(v, CZ_STRING_OCT) << endl;
	tcout << _T("hex,fill: ") << cz_string_U8ToT(v, CZ_STRING_HEX | CZ_STRING_FILL) << endl;
	tcout << _T("hex,prefix: ") << cz_string_U8ToT(v, CZ_STRING_HEX | CZ_STRING_PREFIX) << endl;
	tcout << _T("hex,fill,prefix: ") << cz_string_U8ToT(v, CZ_STRING_HEX | CZ_STRING_FILL | CZ_STRING_PREFIX) << endl;
	tcout << _T("oct,prefix: ") << cz_string_U8ToT(v, CZ_STRING_OCT | CZ_STRING_PREFIX) << endl;
}

void I64To_test(i64 v)
{
	tcout << _T("none: ") << cz_string_I64ToT(v) << endl;
	tcout << _T("hex: ") << cz_string_I64ToT(v, CZ_STRING_HEX) << endl;
	tcout << _T("oct: ") << cz_string_I64ToT(v, CZ_STRING_OCT) << endl;
	tcout << _T("hex,fill: ") << cz_string_I64ToT(v, CZ_STRING_HEX | CZ_STRING_FILL) << endl;
	tcout << _T("hex,prefix: ") << cz_string_I64ToT(v, CZ_STRING_HEX | CZ_STRING_PREFIX) << endl;
	tcout << _T("hex,fill,prefix: ") << cz_string_I64ToT(v, CZ_STRING_HEX | CZ_STRING_FILL | CZ_STRING_PREFIX) << endl;
	tcout << _T("oct,prefix: ") << cz_string_I64ToT(v, CZ_STRING_OCT | CZ_STRING_PREFIX) << endl;
}

void I32To_test(i32 v)
{
	tcout << _T("none: ") << cz_string_I32ToT(v) << endl;
	tcout << _T("hex: ") << cz_string_I32ToT(v, CZ_STRING_HEX) << endl;
	tcout << _T("oct: ") << cz_string_I32ToT(v, CZ_STRING_OCT) << endl;
	tcout << _T("hex,fill: ") << cz_string_I32ToT(v, CZ_STRING_HEX | CZ_STRING_FILL) << endl;
	tcout << _T("hex,prefix: ") << cz_string_I32ToT(v, CZ_STRING_HEX | CZ_STRING_PREFIX) << endl;
	tcout << _T("hex,fill,prefix: ") << cz_string_I32ToT(v, CZ_STRING_HEX | CZ_STRING_FILL | CZ_STRING_PREFIX) << endl;
	tcout << _T("oct,prefix: ") << cz_string_I32ToT(v, CZ_STRING_OCT | CZ_STRING_PREFIX) << endl;
}

void I16To_test(i16 v)
{
	tcout << _T("none: ") << cz_string_I16ToT(v) << endl;
	tcout << _T("hex: ") << cz_string_I16ToT(v, CZ_STRING_HEX) << endl;
	tcout << _T("oct: ") << cz_string_I16ToT(v, CZ_STRING_OCT) << endl;
	tcout << _T("hex,fill: ") << cz_string_I16ToT(v, CZ_STRING_HEX | CZ_STRING_FILL) << endl;
	tcout << _T("hex,prefix: ") << cz_string_I16ToT(v, CZ_STRING_HEX | CZ_STRING_PREFIX) << endl;
	tcout << _T("hex,fill,prefix: ") << cz_string_I16ToT(v, CZ_STRING_HEX | CZ_STRING_FILL | CZ_STRING_PREFIX) << endl;
	tcout << _T("oct,prefix: ") << cz_string_I16ToT(v, CZ_STRING_OCT | CZ_STRING_PREFIX) << endl;
}

void I8To_test(i8 v)
{
	tcout << _T("none: ") << cz_string_I8ToT(v) << endl;
	tcout << _T("hex: ") << cz_string_I8ToT(v, CZ_STRING_HEX) << endl;
	tcout << _T("oct: ") << cz_string_I8ToT(v, CZ_STRING_OCT) << endl;
	tcout << _T("hex,fill: ") << cz_string_I8ToT(v, CZ_STRING_HEX | CZ_STRING_FILL) << endl;
	tcout << _T("hex,prefix: ") << cz_string_I8ToT(v, CZ_STRING_HEX | CZ_STRING_PREFIX) << endl;
	tcout << _T("hex,fill,prefix: ") << cz_string_I8ToT(v, CZ_STRING_HEX | CZ_STRING_FILL | CZ_STRING_PREFIX) << endl;
	tcout << _T("oct,prefix: ") << cz_string_I8ToT(v, CZ_STRING_OCT | CZ_STRING_PREFIX) << endl;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

void String_To_Num_test()
{
	tcout << _T("-------- String_To_Num_test --------") << endl;

	tcout << _T("-- Tou64_test") << endl;
	ToU64_test();
	tcout << endl;

	tcout << _T("-- Tou32_test") << endl;
	ToU32_test();
	tcout << endl;
}

void ToU64_test()
{
	tcout << dec << _T("none: ") << cz_string_TToU64(_T("1234567812345678")) << endl;
	tcout << hex << _T("hex: 0x") << cz_string_TToU64(_T("0x1a2b3c4d5e6f7890"), CZ_STRING_HEX) << endl;
	tcout << oct << _T("oct: 0") << cz_string_TToU64(_T("011227733445566"), CZ_STRING_OCT) << endl;
}

void ToU32_test()
{
	tcout << dec << _T("none: ") << cz_string_TToU32(_T("1234")) << endl;
	tcout << hex << _T("hex: 0x") << cz_string_TToU32(_T("0x1122abcd"), CZ_STRING_HEX) << endl;
	tcout << oct << _T("oct: 0") << cz_string_TToU32(_T("011227"), CZ_STRING_OCT) << endl;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

void Check_test()
{
	tcout << _T("-------- Check_test --------") << endl;

	tcout << _T("-- IsVisible_test") << endl;
	IsVisible_test();
	tcout << endl;
}

void IsVisible_test()
{
	tchar tc;
	for (tc = 0; tc < 127; ++tc)
	{
		tcout << (u32)tc << _T(" ") << tc << _T(" ") << cz_string_IsVisibleT(tc) << _T("\t\t");
		if ((tc % 4) == 3) tcout << endl;
	}
}